package cn.gailvlun.gll.presentation.xroom.adapter

import android.graphics.Rect
import android.support.annotation.Px
import android.support.v7.widget.RecyclerView
import android.view.View

class GridItemDecoration(@Px val spaceHeight: Int, val column: Int): RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)

        with(outRect) {
            if (column > parent.getChildAdapterPosition(view)) {
                top = 0
            }
            if (parent.getChildAdapterPosition(view) % column == 0) {
                left = 0
                right = spaceHeight
            } else {
                left = spaceHeight
                right = 0
            }
            bottom = spaceHeight
        }

    }
}